
using BasicRedis.Caches;
using BasicRedis.Contexts;
using Microsoft.EntityFrameworkCore;

namespace BasicRedis
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();
            builder.Services.AddSwaggerGen();
            builder.Services.AddDbContextPool<ProductDbContext>(option =>
            {
                option.UseMySql("server=127.0.0.1;port=3306;database=RedisEFCore;uid=root;pwd=123456", new MySqlServerVersion("8.1.0-mysql"));
                //option.UseSqlServer("Data Source=192.168.60.132;Initial Catalog=Redis;Password=zdf19980525.;User ID=sa;Trust Server Certificate=True");
                //option.UseMySql("server=192.168.60.132;port=3306;database=RedisEFCore;uid=root;pwd=123456", new MySqlServerVersion("5.7.44-mysql"));
                option.UseLoggerFactory(LoggerFactory.Create(x => x.AddConsole()));
            });

            builder.Services.AddMemoryCache();
            // 1、redis连接
            //builder.Services.AddDistributedRedisCache("192.168.60.132:6379");
            builder.Services.AddDistributedRedisCache("20.119.74.247:7001");
            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseAuthorization();


            app.MapControllers();

            app.Run();
        }
    }
}
